package cz.gelion.shylock.invoice.web.subj

import org.apache.wicket.markup.html.panel.Panel
import cz.gelion.shylock.invoice.Log
import org.apache.wicket.model.IModel
import cz.gelion.shylock.invoice.entity.Subject
import cz.gelion.shylock.invoice.web.comp.TaForm
import org.apache.wicket.markup.html.form.TextField
import org.apache.wicket.markup.html.form.TextArea
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink
import org.apache.wicket.ajax.AjaxRequestTarget
import org.apache.wicket.markup.html.form.Form
import org.apache.wicket.model.CompoundPropertyModel
import org.apache.wicket.Component

class SubjectEditorPanel (id:String, model:IModel[Subject], val feedback:()=>Component=null, val submit:Subject=>Unit=(t:Subject)=>{}) extends Panel(id,model) with Log {
   
  log.trace("this(" + id + "," + model + ")")
  
  val form = new TaForm[Subject]("form", new CompoundPropertyModel(model),submit) 
  
  add(form)
  form.setOutputMarkupId(true)
  
  form.add(new TextField("prefix"))
  form.add(new TextField("name").setRequired(true))
  form.add(new TextField("givenname"))		
  form.add(new TextField("suffix"))
  form.add(new TextField("street"))
  form.add(new TextField("city"))
  form.add(new TextField("district"))
  form.add(new TextField("state"))
  form.add(new TextField("postcode"))
  form.add(new TextField("taxno"))
  form.add(new TextField("idno"))
  form.add(new TextArea("note"))
  
  form.add(new AjaxSubmitLink("link.ok") {
    
    override def onSubmit(target:AjaxRequestTarget, form:Form[_]) {
      log.trace("AjaxSumitLink[link.ok].onSubmit");
      target.add(form)
     
    }
    
     override def onError(target:AjaxRequestTarget, form:Form[_]) {
      log.trace("AjaxSumitLink[link.ok].onError");
      log.trace("updating component: " + feedback)
      if (feedback != null) target.add(feedback())
    }
    
  });
  
}